package com.itheima.tliaswebmanagement.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

//@WebFilter(urlPatterns = "/login")
public class AbcFilter implements Filter {
    //初始化方法，web服务器启动，创建Filter实例时调用，只会调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init....");
    }

    //拦截到请求时，调用该方法，可以调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("1.AbcFilter放行前...");
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("4.AbcFilter放行后...");
    }

    //销毁方法，web服务器关闭时调用，只会调用一次
    @Override
    public void destroy() {
        System.out.println("destroy...");
    }
}
